build-phar

#!/usr/bin/env bash
# MUST BE RUN FROM PROJECT ROOT
#


if [[ ! -d build ]];then
    mkdir build
fi

if [[ ! -f "build/phar-composer-1.4.0.phar" ]]; then
    phar_composer_url="https://github.com/clue/phar-composer/releases/download/v1.4.0/phar-composer-1.4.0.phar"
    if [[ "$1" == "--build-phar" ]];then 
        answer="y";
    else
        read -p \
        "
        phar-composer is not installed. 
        Download from $phar_composer_url? 
        (y/n)" \
        answer
    fi

    if [[ "$answer" == "y" || "$answer" == "Y" ]];then
        cd build;
        curl -JOL $phar_composer_url 
        cd ..;
    else
        echo "Can't create phar without installing phar-composer. Try again."
        exit
    fi

fi

if [[ -f build/scrawl.phar ]];then
    rm build/scrawl.phar
fi
php -d phar.readonly=0 build/phar-composer-1.4.0.phar build "$(pwd)/"
git_hash="git rev-parse --short HEAD"
mv code-scrawl.phar "build/scrawl.phar"

echo "

    bin/scrawl.phar created

"